package com.situ.java.service;

import java.io.Serializable;

import com.situ.java.domain.Person;

public class PersonListService implements Serializable{
    /** serialVersionUID*/  
    private static final long serialVersionUID = 16511L;
    
    static Person[] persons = new Person[1024];// 借书卡数组，暂时设置上限为1024人
    static int totalPerson = 0;


    //遍历借书卡
    public Person[] getPersons(){
        Person[] persons = new Person[totalPerson];// 返回存在是图书
        for (int i = 0; i < persons.length; i++) {
            persons[i] = this.persons[i];
        }
        return persons;
    }


    //添加借书卡
    public void addPerson(Person p) throws MyException {
        for (int i = 0; i < totalPerson; i++) {
            if (p.getId()==persons[i].getId())
                throw new MyException("该借书卡ID已存在，无法添加");
        }
        if (p instanceof Person)
            persons[totalPerson++] = p;
    }
}
